package com.baizhi.service.impl;

import com.baizhi.entity.PmsAttrGroup;
import com.baizhi.entity.PmsCategory;
import com.baizhi.mapper.PmsAttrGroupMapper;
import com.baizhi.mapper.PmsCategoryMapper;
import com.baizhi.service.IPmsAttrGroupService;
import com.baizhi.vo.PmsAttrGroupVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 属性分组 服务实现类
 * </p>
 *
 * @author yu
 * @since 2020-09-24
 */
@Service
public class PmsAttrGroupServiceImpl extends ServiceImpl<PmsAttrGroupMapper, PmsAttrGroup> implements IPmsAttrGroupService {
    @Autowired
    private PmsAttrGroupMapper pmsAttrGroupMapper;
    @Autowired
    private PmsCategoryMapper pmsCategoryMapper;
    @Override
    public void insert(PmsAttrGroupVo pmsAttrGroupVo) {
        PmsAttrGroup pmsAttrGroup = new PmsAttrGroup();
        BeanUtils.copyProperties(pmsAttrGroupVo,pmsAttrGroup);
        QueryWrapper<PmsCategory> wrapper = new QueryWrapper<>();
        wrapper.eq("name",pmsAttrGroupVo.getCategoryName());
        PmsCategory pmsCategory = pmsCategoryMapper.selectOne(wrapper);
        Long catId = pmsCategory.getCatId();
        pmsAttrGroup.setCategoryId(catId);
        pmsAttrGroupMapper.insert(pmsAttrGroup);
    }
}
